package edu.cmu.cs.stage3.alice.authoringtool.util;

public class PropertyUndoableRedoable implements ContextAssignableUndoableRedoable {
	protected edu.cmu.cs.stage3.alice.core.Property property;
	protected Object oldValue;
	protected Object newValue;
	protected Object context;

	

	public PropertyUndoableRedoable( edu.cmu.cs.stage3.alice.core.Property property, Object oldValue, Object newValue ) {
		this.property = property;
		this.oldValue = oldValue;
		this.newValue = newValue;
	}

	public void setContext( Object context ) {
		this.context = context;
	}

	public void undo() {
		property.set( oldValue );
	}

	public void redo() {
		property.set( newValue );
	}

	public Object getAffectedObject() {
		return property.getOwner();
	}

	public Object getContext() {
		return context;
	}

	//Rem @Override
	public String toString() {
		StringBuffer s = new StringBuffer();
		s.append( "edu.cmu.cs.stage3.alice.authoringtool.util.PropertyUndoableRedoable[ " );
		s.append( "property=" + property + "; " );
		s.append( "oldValue=" + oldValue + "; " );
		s.append( "newValue=" + newValue + "; " );
		if( (context != this) && !(context instanceof DefaultUndoRedoStack) ) {  // watch out for infinite loops
			s.append( "context=" + context + "; " );
		} else {
			s.append( "context=" + context.getClass() + "; " );
		}
		s.append( " ]" );
		return s.toString();
	}
}